<?php
/*
 * filesys.php
 *
 * Copyright (C) 2006 - OS3 srl - http://www.os3.it
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
function filesys_exists ( $name )
{
	if ( file_exists ( $name ) )
		return ( true );
	
	return ( false );
}

function filesys_mkdir ( $name )
{
	if ( filesys_exists ( $name ) ) return ( true );

	if ( mkdir ( $name, 0755 ) == true ) return ( true );

	util_display_error ( "Errore durante la creazione della directory", $name );

	return ( false );
}

function filesys_copy ( $from, $to, $mode = 0644 )
{
	if ( copy ( $from, $to ) == true ) 
	{
		chmod ( $to, $mode );
		return ( true );
	}

	util_display_error ( "Errore durante la copia.", "File Originale: $from<br>Destinazione: $to" );

	return ( false );
}

function filesys_copy_all ( $from, $to )
{
	$files = util_scan_dir ( $from, false, true );

	reset ( $files );

	foreach ( $files as $name )
	{
		filesys_copy ( $from . "/" . $name, $to . "/" . $name );
	}
}

function filesys_move ( $from, $to )
{
	filesys_copy ( $from, $to );
	filesys_del ( $from );
}

function filesys_del_all ( $from )
{
	$files = util_scan_dir ( $from, false, true, true );

	foreach ( $files as $f ) filesys_del ( $from . "/" . $f );
}

function filesys_del ( $fname )
{
	return ( @ unlink ( $fname ) );
}

function filesys_del_dir ( $fname )
{
	return ( @ rmdir ( $fname ) );
}
?>
